﻿using System;
using Company.BLL;
using Company.BLL.KDT.GC;
using Company.BLL.Utils;
using Company.BLL.DuLieuChuan;


namespace Company.Interface.KDT.GC.PCTFormTemplate
{
    public partial class PKGiahanHDForm : BaseForm
    {
        public HopDong hopdong = new HopDong();
        public Company.BLL.KDT.GC.PhuKienDangKy pkdk = new Company.BLL.KDT.GC.PhuKienDangKy();
        public bool isAdd = true;
        public PKGiahanHDForm()
        {
            InitializeComponent();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            isAdd = false;
            this.Close();
        }


        private void txtMaHS_Leave(object sender, EventArgs e)
        {
            if (!MaHS.Validate(txtMaHS.Text, 10))
            {
                error.SetIconPadding(txtMaHS, -8);
                error.SetError(txtMaHS, "Mã số HS không hợp lệ.");
            }
            else
            {
                error.SetError(txtMaHS, string.Empty);
            }
        }

        private void PKGiahanHDForm_Load(object sender, EventArgs e)
        {
            if (!isAdd)
            {
                btnAdd.Text = "Sửa";
                txtThongTinMoi.Text = pkdk.ThongTinMoi;
                txtGhiChu.Text = pkdk.GhiChu;
                txtVBCP.Text = pkdk.VBCP;
            }
            txtMaDV.Text = GlobalSettings.MA_DON_VI;
            txtTenDv.Text = GlobalSettings.TEN_DON_VI;
            txtSoTiepNhan.Text = pkdk.SoTiepNhan.ToString();
            txtSoHopDong.Text = hopdong.SoHopDong;
            txtSoPhuKien.Text = pkdk.SoPhuKien.ToString();
            ccNgayKyHD.Text = hopdong.NgayKy.ToShortDateString();
            ccNgayPhuKien.Text = pkdk.NgayPhuKien.ToShortDateString();
            ctrDonViHaiQuan.Ma = hopdong.MaHaiQuan;
            if (pkdk.TrangThaiXuLy == TrangThaiXuLy.CHO_DUYET)
            {
                lblTrangThai.Text = "Chờ duyệt";
            }
            else if (pkdk.TrangThaiXuLy == TrangThaiXuLy.CHUA_KHAI_BAO)
            {
                lblTrangThai.Text = "Chưa khai báo";
            }
            else if (pkdk.TrangThaiXuLy == TrangThaiXuLy.DA_DUYET)
            {
                lblTrangThai.Text = "Đã duyệt";
                btnAdd.Enabled = false;
            }
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            cvError.Validate();
            if (!cvError.IsValid) return;          
            pkdk.VBCP = txtVBCP.Text.Trim();
            pkdk.GhiChu = txtGhiChu.Text.Trim();
            pkdk.ThongTinMoi = txtThongTinMoi.Text.Trim();            
            this.Close();
        }
    }
}
